/**
 * Copyright (C) 2017 - 2020 https://github.com/joewee
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.entity;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 *交易发送log表
 *
 *@author joewee
 *@version 1.0.0
 *@Date 2018/5/18 17:04
 */
@Entity
@Table(name = "TRANSACTION_SEND_LOG",indexes = {
        @Index(name = "ID_SUCCESS_INDEX",columnList = "ID,IS_SUCCESS",unique = true),
        @Index(name = "ORDER_ID_TYPE_INDEX",columnList = "ORDER_ID,TYPE",unique = true),
        @Index(name = "TRANS_NUMBER_INDEX",columnList = "TRANS_NUMBER",unique = true)
})
public class TransactionSendLog {
    public static final String LOCK_KEY = "com.bifrost.transactionSendLog.lock";
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", unique = true, nullable = false)
    private Long id;

    @Column(name = "ORDER_ID")
    private Long orderId;

    @Column(name = "TOTAL")
    private BigDecimal total;

    @Column(name = "TOTAL_SHIPPING")
    private BigDecimal totalShippingFee;

    @Column(name = "TRANS_NUMBER",length = 20)
    private String transNumber;

    @Column(name = "STROE_CODE",length = 8,nullable = false)
    private String stroeCode;

    @Column(name = "TYPE",length = 16)
    @Enumerated(value = EnumType.STRING)
    private Type type;

    @Column(name = "REMARK")
    private String remark;

    //创建时间
    @Column(name = "CREATE_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate = new Date();
    //发送时间
    @Column(name = "SEND_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date sendDate ;

    @Column(name = "IS_SUCCESS",nullable = false)
    private Boolean success = Boolean.FALSE;

    @Column(name = "RICHBASE_RECEIPT_SEND")
    private Boolean richBaseReceipt = Boolean.FALSE;

    @Column(name = "RICHBASE_RECEIPT_SEND_DATE")
    private Date richBaseReceiptSendDate;

    @Column(name = "REPORT_SEND_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date reportSendDate;

    @Column(name = "IS_REPORT_SEND_SUCCESS",nullable = false)
    private Boolean reportSendSuccess = Boolean.FALSE;

    @Column(name="SEND_RECORD_STATUS" , length = 1 )
    private String sendRecordStatus= "N" ;

    @Column(name="SEND_RECORD_REMARK")
    private String sendRecordRemark;

    public Date getReportSendDate() {
        return reportSendDate;
    }

    public void setReportSendDate(Date reportSendDate) {
        this.reportSendDate = reportSendDate;
    }

    public Boolean getReportSendSuccess() {
        return reportSendSuccess;
    }

    public void setReportSendSuccess(Boolean reportSendSuccess) {
        this.reportSendSuccess = reportSendSuccess;
    }

    public enum Type{
        SALES,CANCEL,REFUND;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public String getTransNumber() {
        return transNumber;
    }

    public void setTransNumber(String transNumber) {
        this.transNumber = transNumber;
    }

    public String getStroeCode() {
        return stroeCode;
    }

    public void setStroeCode(String stroeCode) {
        this.stroeCode = stroeCode;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getSendDate() {
        return sendDate;
    }

    public void setSendDate(Date sendDate) {
        this.sendDate = sendDate;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public BigDecimal getTotal() {
        return total;
    }

    public void setTotal(BigDecimal total) {
        this.total = total;
    }

    public String getSendRecordStatus() {
        return sendRecordStatus;
    }

    public void setSendRecordStatus(String sendRecordStatus) {
        this.sendRecordStatus = sendRecordStatus;
    }

    public String getSendRecordRemark() {
        return sendRecordRemark;
    }

    public void setSendRecordRemark(String sendRecordRemark) {
        this.sendRecordRemark = sendRecordRemark;
    }

    public BigDecimal getTotalShippingFee() {
        return totalShippingFee;
    }

    public void setTotalShippingFee(BigDecimal totalShippingFee) {
        this.totalShippingFee = totalShippingFee;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TransactionSendLog that = (TransactionSendLog) o;

        if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) return false;
        if (getOrderId() != null ? !getOrderId().equals(that.getOrderId()) : that.getOrderId() != null) return false;
        if (getTransNumber() != null ? !getTransNumber().equals(that.getTransNumber()) : that.getTransNumber() != null)
            return false;
        if (getStroeCode() != null ? !getStroeCode().equals(that.getStroeCode()) : that.getStroeCode() != null)
            return false;
        return getType() == that.getType();
    }

    @Override
    public int hashCode() {
        int result = getId() != null ? getId().hashCode() : 0;
        result = 31 * result + (getOrderId() != null ? getOrderId().hashCode() : 0);
        result = 31 * result + (getTransNumber() != null ? getTransNumber().hashCode() : 0);
        result = 31 * result + (getStroeCode() != null ? getStroeCode().hashCode() : 0);
        result = 31 * result + (getType() != null ? getType().hashCode() : 0);
        return result;
    }

    public Boolean getRichBaseReceipt() {
        return richBaseReceipt;
    }

    public void setRichBaseReceipt(Boolean richBaseReceipt) {
        this.richBaseReceipt = richBaseReceipt;
    }

    public Date getRichBaseReceiptSendDate() {
        return richBaseReceiptSendDate;
    }

    public void setRichBaseReceiptSendDate(Date richBaseReceiptSendDate) {
        this.richBaseReceiptSendDate = richBaseReceiptSendDate;
    }
}
